<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>XGG管理系统</title>

  <link rel="shortcut icon" th:href="@{/images/favicon.ico}"/>
  <link rel="stylesheet" th:href="@{/assets/css/plugins/sweetalert/sweetalert.css}"/>
  <link th:href="@{/assets/css/bootstrap.min.css}" rel="stylesheet">
  <link th:href="@{/assets/css/font-awesome.min.css}" rel="stylesheet">
  <link th:href="@{/assets/css/animate.min.css}" rel="stylesheet">
  <link th:href="@{/assets/css/login.css}" rel="stylesheet">
  <link th:href="@{/assets/css/style.min.css}" rel="stylesheet">
  <link th:href="@{/assets/css/plugins/toastr/toastr.min.css}" rel="stylesheet">
  <style th:inline="text">
      body {
          /*background: #1c84c6;*/
          height: auto;
          /*background: url("[[@{/assets/img/back3.jpeg}]]") no-repeat center fixed;*/
          background-color:#1c84c6;
          -webkit-background-size: cover;
          -moz-background-size: cover;
          -o-background-size: cover;
          background-size: cover;
          /*color: rgba(255, 255, 255, .95);*/
      }

      .uname {
          background: #fff url("[[@{/assets/img/user.png}]]") no-repeat 95% center;
          color: #000;
      }

      .pword {
          background: #fff url("[[@{/assets/img/locked.png}]]") no-repeat 95% center;
          color: #000;
      }
  </style>

  <!--[if lt IE 9]>
  <meta http-equiv="refresh" content="0;ie.html"/>
  <![endif]-->
  <script>if (window.top !== window.self) {
      window.top.location = window.location;
  }</script>

</head>
<body class="signin">
<div class="signinpanel">
  <form method="post" id="loginFrom">
    <h1 class="no-margins" style="text-align: center;color: #1a7bb9"><B> XGG 管 理 系 统 </B></h1>
    <input id="username" name="username" minlength="2" type="text" required class="form-control uname" placeholder="用户名"/>
    <input id="password" name="password" minlength="6" type="password" required class="form-control pword m-b" placeholder="密码"/>
    <!--<a href="">忘记密码了？</a>-->
    <div class="input-group m-t m-b">
      <input id="captcha" type="text" class="form-control no-margins" required placeholder="验证码">
      <span class="input-group-addon no-padding"><img id="captchaImg" onclick="getCaptcha()" height="32"></span>
    </div>
    <button class="btn btn-primary btn-block" onclick="doLogin()" type="button">登录</button>
  </form>
</div>
</body>
<script th:src="@{/assets/js/jquery.min.js?v=2.2.0}"></script>
<script th:src="@{/assets/js/bootstrap.min.js}"></script>
<script th:src="@{/assets/js/plugins/validate/jquery.validate.min.js}"></script>
<script th:src="@{/assets/js/plugins/validate/messages_zh.min.js}"></script>
<script th:src="@{/assets/js/inputValidate.js}"></script>
<script th:src="@{/assets/js/plugins/sweetalert/sweetalert.min.js}"></script>
<script th:src="@{/assets/js/plugins/toastr/toastr.min.js}"></script>
<script th:src="@{/assets/js/plugins/md5/md5.js}"></script>
<script th:src="@{/assets/js/jsencrypt.min.js}"></script>
<script th:src="@{/assets/js/index.js}"></script>
<script th:inline="javascript">
  var uuid ;

  $(document).keyup(function(event){
    if(event.keyCode ==13){
      doLogin()
    }
  });

  $(function () {



    toastr.options = {
      "closeButton": true,
      "debug": false,
      "progressBar": true,
      "positionClass": "toast-top-center",
      "onclick": null,
      "showDuration": "400",
      "hideDuration": "1000",
      "timeOut": "2000",
      "extendedTimeOut": "1000",
      "showEasing": "swing",
      "hideEasing": "linear",
      "showMethod": "fadeIn",
      "hideMethod": "fadeOut"
    }

    getCaptcha();//获取验证码
  });

  function getCaptcha(){
    uuid = getUUID();
    const captcha_url =/*[[@{/sys/login/captcha.jpg}]]*/
    $("#captchaImg")[0].src = captcha_url+"?uuid="+uuid;
  }
    //登录跳转
    /*function userLogin() {
        if ($("#loginForm").valid()) {
            $("#loginForm").submit();
        }
    }*/
  function doLogin(){

    var username = $("#username").val();
    var password = $("#password").val();
    var captcha = $("#captcha").val();
    if(username!=""){}else{
      toastr.error('请输入登录用户名！！！')
      return;
    }
    if(password!=""){}else{
      toastr.error('请输入登录密码！！！')
      return;
    }
    if(captcha!=""){}else{
      toastr.error('请输入登录验证码！！！')
      return;
    }
    var passwd = encrypt($.md5(password)+"-"+new Date().getTime());

    $.ajax({
      type: "post",
      url: "sys/login",
      data: {
        "username": username,
        "password": passwd,
        "captcha": captcha,
        "uuid": uuid
      },
      dataType: "json",
      success: function (data) {
        getCaptcha()
        if(data.success){
          //toastr.success(data.message)
          self.location='main';
        }else{
          toastr.error(data.message)
        }

      },
      error: function (data){
        toastr.error(data.message)
      }
    })
  }

  function getUUID () {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
      })
  }
</script>
</html>